package com.cat.dataStructure;

import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Deque;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/reveal-cards-in-increasing-order/
 * @create 2025/9/19 22:26
 * @since JDK17
 */

public class Solution69 {
        public int[] deckRevealedIncreasing(int[] deck) {
            int n = deck.length;
            int[] ans = new int[n];
            Deque<Integer> q = new ArrayDeque<>();
            for (int i = 0; i < n; i++) {
                q.offer(i);
            }
            Arrays.sort(deck);
            for (var x : deck) {
                ans[q.pollFirst()] = x;
                if (!q.isEmpty()) {
                    q.offer(q.pollFirst());
                }
            }

            return ans;
        }
    }